<template>
	<view class="homecode">
		<view class="" style="height: 40rpx;">
			
		</view>
		<view class="nav-top">
			<text @click="navback" class="iconfont todayfanhui"></text>
			<text v-if="isnext" @click="submit" class="next">完成</text>
		</view>
		<view class="m_header_top"></view>
		<view class="codecontent">
			<!-- 头像名称 -->
			<view class="headertop" v-if="!isnext">
				<image class="image" src="../../../../static/img/asd.png" mode=""></image>
				<view class="name">
					王大壮
				</view>
				<view class="distraction">
					你即将关注王大壮的日程
				</view>
				<view class="button_guanzhu" @click="nextmember">
					马上关注
				</view>
			</view>
			<!-- 切换 -->
			<view class="headertop" v-else>
				<view class="title">
					你是王大壮的
				</view>
				<scroll-view class="scrolltop" scroll-y="true" style="height:50vh;">
					<view>
						<view class="boxcontent">
							<view class="box" @click="btncheck(item)" v-for="item in relationlist" :class="item.code==checkmember?'defau':''">
								<text>{{item.name}}</text>
							</view>
							<view v-if="!ischeck" class="box" @click="btnshowmore()">
								<text>展开</text>
							</view>
						</view>
					</view>
				</scroll-view>
				
			</view>
		</view>
	</view>
</template>

<script>
	import {
		selectallrelation,
		addChildRoleRegulateTb
	} from "@/api/api.js";
	import {formModule } from '@/utils/formdata.js'
	var fromdata = new formModule();
	import {
		mapState,
		mapActions,
		mapGetters,
		mapMutations
	} from 'vuex';
	export default {
		data(){
			return {
				checkmember:'',
				ischeck:false,
				isnext:false,
				relationlist:[],
				childInfo:{}
			}
		},
		computed:{
			...mapState('initData', {
				// scheduleList: state => state.scheduleList,
				currentUser: state => state.currentUser,
			}),
		},
		onLoad(e) {
			if(e.data){
				this.childInfo =JSON.parse(e.data);
			}
			console.log('假如参数',JSON.parse(e.data))
			this.indata(9)
		},
		methods:{
			async indata(pageSize){
				let result = await selectallrelation({pageNum:1,pageSize:pageSize,userId:this.currentUser.userId});
				result = fromdata.formatDate(result);
				this.relationlist = result.list;
			},
			submit(){
				let {childId,regulateId} = this.childInfo;
					addChildRoleRegulateTb(
					{
						"childId": childId,
						"regulateId":this.checkmember,
						"userId": this.currentUser.userId
					}
				).then(res=>{
					if(res.data.code == 0){
						uni.showToast({
							title:'共享成功',
							icon:'none'
						})
						uni.navigateBack({
							delta:2
						})
					}else{
						uni.showToast({
							title:'共享失败'+res.data.msg,
							icon:'none'
						})
					}
				})
			},
			btncheck(val){
				console.log(val)
				this.checkmember = val.code
			},
			btnshowmore(){
				this.indata(100)
				this.ischeck =true
			},
			nextmember(){
				this.isnext = true
			},
			navback(){
				if(this.isnext){
					this.isnext =false;
					return
				}
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nav-top{
		height: 88rpx;
		display:flex;
		justify-content:space-between;
		align-items: center;
		padding: 0 16rpx;
		.next{
			width: 166rpx;
			height:60rpx;
			line-height: 60rpx;
			border-radius: 30rpx;
			background-color: rgba(4, 161, 251, 1);
			font-size: 34rpx;
			font-family: PingFang SC;
			font-weight: 500;
			text-align: center;
			color: #FFFFFF;
			opacity: 1;

		}
	}
	.homecode{
		background-color: #FFFFFF;
		min-height: 100vh;
	}
	.codecontent{
		display: flex;
		flex-flow: row wrap;
		justify-content: center;
		background-color: #FFFFFF;
		.scrolltop{
			margin-top: 135rpx;
		}
		.headertop{
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			.title{
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #121212;
				opacity: 1;
			}
			.boxcontent{
				display: flex;
				flex-flow: row wrap;
				justify-content: center;
				.defau{
						background-color: rgba(4, 161, 251, 1) !important;
						color: #FFFFFF !important;
				}
				.box{
					width: 300rpx;
					height: 100rpx;
					text-align: center;
					background-color:rgba(248, 248, 248, 1);
					// margin-top: 16rpx;
					margin: 16rpx 23rpx 0;
					text-align: center;
					line-height: 100rpx;
					border-radius:4rpx;
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: rgba(51, 51, 51, 1);
					opacity: 1;
				}
			}
			
			.name{
				margin-top: 16rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				opacity: 1;

			}
			.image{
				width: 188rpx;
				height: 188rpx;
				border-radius: 50%;
			}
			.button_guanzhu{
				margin-top: 80rpx;
				width: 686rpx;
				font-size: 40rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				opacity: 1;
				text-align: center;
				height: 88rpx;
				border-radius: 20rpx;
				background-color: rgba(4, 161, 251, 1);
				line-height: 88rpx;
			}
			.distraction{
				margin-top: 40rpx;
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #121212;
				opacity: 1;

			}
		}
	}
</style>
